using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIMenu : MonoBehaviour
{
    [SerializeField] Transform mPivot;

    public void OnClickAttack()
    {
        PlayerController.Instance.ShowPathAttack();
        gameObject.SetActive(false);
        //OnClickClose();
    }

    public void OnClickFinish()
    {
        PlayerController.Instance.OnFinishAction();
        OnClickClose();
    }

    public void OnClickClose()
    {
        PlayerController.Instance.CancelAction();
        gameObject.SetActive(false);
    }

    public void SetData(Hero hero)
    {
        gameObject.SetActive(true);
        Vector2 origin = hero.transform.position;
        origin = new Vector2(Mathf.RoundToInt(origin.x + 0.5f) - 0.5f, Mathf.RoundToInt(origin.y + 0.5f) - 0.5f);

        var center = mPivot.transform.position;
        Transform active_entry = null;
        for (int i = transform.childCount - 1; i >= 0; i--)
        {
            var child = transform.GetChild(i);
            if (child.gameObject.activeSelf)
            {
                active_entry = child;
                break;
            }
        }
        var offset = center - active_entry.position;
        mPivot.position = origin; 
    }
}
